package com.zhiwen.test;

/**
 * @Auther: wuzhiwen
 * @Date: 2018/12/21 14:13
 * @Description:
 */
public class QuickSort {

    public static void main(String[] args) {
        int[] arraySort = {8, 3, 4, 0, 6, 7, 1, 2, 12, 9};
        quitsort(arraySort, 0, arraySort.length - 1);
        for (int i : arraySort) {
            System.out.println(i);
        }
    }

    //根据快速排序的思想先自己实现
    public static void quitsort(int[] arr, int left, int right) {
        if (left > right)
            return;
        int i = left;
        int j = right;
        int temp = arr[left];
        while (i != j) {

            while (arr[i] <= temp && i < j) {
                i++;
            }
            while (arr[j] >= temp && i < j) {
                j--;
            }
            if (i < j) {
                int tem = arr[i];
                arr[i] = arr[j];
                arr[j] = tem;
            }
        }
        arr[left] = arr[i];
        arr[i] = temp;
        quitsort(arr, left, i - 1);
        quitsort(arr, i + 1, right);
    }
}